/**
 * 
 */
package cn.netjava.thread;

/**
 * @author admin
 *
 */
import java.util.*;
import java.io.*;
public class FindFiles extends Thread {
	List<String> filesList=new ArrayList<String>();
	
	private String scr;
	
	private String suffix;
	
	public FindFiles(String scr,String suffix){
		this.scr=scr;
		this.suffix=suffix;
	}
	
	public List<String> findfiles(String scr,String suffix){
		File fileName=new File(scr);
		if(fileName==null){
			return filesList;
		}
		if(fileName.isDirectory()){
			File[] files=fileName.listFiles();
			if(files==null){
				return filesList;
			}
			for(int i=0;i<files.length;i++){
				if(files[i].isDirectory()){
					String name=files[i].getAbsolutePath();
					findfiles(name,suffix);
				}
				else{
					String filename=files[i].getAbsolutePath();
					if(filename.endsWith(suffix)){
						filesList.add(filename);
						
					}
					
				}
			}
		}
		else{
			String filesName=fileName.getAbsolutePath();
			if(filesName.endsWith(suffix)){
				filesList.add(filesName);
				
			}
		}
		return filesList;
	}
	public void output(){
		for(int i=0;i<filesList.size();i++){
		String s=filesList.get(i);
		System.out.println("gogo");
		System.out.println(s);
		}
	}
	
	public List<String> getlist(){
		return filesList;
	}
	public void run(){
		findfiles(scr,suffix);
		output();	
		
	}

}
